package com.lv.pojo;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

@Data
@NoArgsConstructor
public class User implements UserDetails, Serializable {
    private String username;//用户名
    private String password;//密码
    private String address;
    private Integer phoneNumber;
    private String roles;//角色

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {//GrantedAuthority里存储的是用户的角色，以字符串的形式
        ArrayList<GrantedAuthority>list=new ArrayList<>();
        list.add(new SimpleGrantedAuthority("ROLE_"+roles));//角色名前必须加上ROLE_,不然security会识别不出来
        return list;
    }
//这四个是判断用户的账号状态
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
